<?php
/*
// 如果使用该方法 则会结果会输出 a a
trait Singleton
{
    private static $instance;

    static function getInstance(...$args)
    {
        if(!isset(self::$instance)){
            self::$instance = new static(...$args);
        }
        return self::$instance;
    }
}
 */


trait Singleton
{
    private static $instance=[];

    static function getInstance(...$args)
    {
    	$obj_name = static::class;
        if(!isset(self::$instance[$obj_name])){
            self::$instance[$obj_name] = new static(...$args);
        }
        return self::$instance[$obj_name];
    }
}

class base
{
	protected $table;
	public function getTable()
	{
		var_dump($this->table);
	}
}


class A extends base
{
	protected $table = 'a';
	use Singleton;
}

class B extends base
{
	protected $table = 'b';
	use Singleton;
}

A::getInstance()->getTable();
B::getInstance()->getTable();